package com.app.dao.impl;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.stereotype.Repository;
import org.springframework.util.Assert;

import com.app.dao.CompanyDao;
import com.app.entity.Company;

@Repository("companyDao")
public class CompanyDaoImpl extends HibernateDaoSupport implements CompanyDao{
	private final Logger logger = LoggerFactory.getLogger(getClass());
	
	@SuppressWarnings("unchecked")
	public Company findComany() {
		List<Company> list = getHibernateTemplate().find("from Company");
		if(list != null && list.size()>0){
			logger.debug("查询公司信息成功！");
			return list.get(0);
		} else {
			throw new RuntimeException("查询公司信息失败！");
		}
	}

	public void updateCompany(Company company) {
		logger.debug("修改公司信息");
		Assert.notNull(company.getId());
		getHibernateTemplate().update(company);
	}

	public Company load(Integer id) {
		return (Company) getHibernateTemplate().load(Company.class, id);
	}

}
